import 'package:flutter/material.dart';
import 'package:flutter_shop/model/category_page_data.dart';
import '../model/category_page_data.dart';

class CartSubNavList with ChangeNotifier {
  List<CategorySubDataModel> navList;

  setCartSubNavList(List<CategorySubDataModel> list) {
    CategorySubDataModel _navItem = CategorySubDataModel();
    _navItem.mallSubId = '';
    _navItem.mallCategoryId = '';
    _navItem.mallSubName = '全部';
    _navItem.comments = null;

    this.navList = [_navItem, ...list];
    notifyListeners();
  }

  // navElement 当前选中的二级类目对象
  // id 选中的一级类目的id
  getCartSubNavList({String id = '0001'}) {
    var _element = CategoryData.where((element) {
      return element['mallCategoryId'] == id;
    });

    if (_element != null) {
      CategorySubListDataModel _list = CategorySubListDataModel.fromJson(_element.toList()[0]['children']);
      setCartSubNavList(_list.data);
    }
  }
}